package demo12String案例演示;
/*
   *已知String str = "this is a text";
1.将str中的单词单独获取出来
2.将str中的text替换为practice
3.在text前面插入一个easy
4.将每个单词的首字母改为大写
*/

/**
 * @author gjw
 */
public class Demo05 {
    public static void main(String[] args) {

        String str = "this is a text";
        //1 将str中的单词单独获取出来
        String[] arr = str.split(" ");
        for ( String sring: arr) {
            System.out.println(sring);
        }

        //2.将str中的text替换为practice
        System.out.println("========================================================");
        String str2 = str.replace("text", "practice");
        System.out.println(str2);

        //3.在text前面插入一个easy
        System.out.println("========================================================");
        String str3 = str.replace("text", "easy text");
        System.out.println(str3);

        //4.将每个单词的首字母改为大写
        System.out.println("========================================================");
        for (int i = 0;i <arr.length; i++){
            char frist = arr[i].charAt(0);
            //把第一个字符转成大写
            char upperfirst = Character.toUpperCase(frist);
            String news = upperfirst+arr[i].substring(1);
            System.out.println(news);
        }

    }
}
